Namespace persistent
    Public Class updateReason

        Public Shared Function getGridData(ByVal coid As String) As DataTable
            Dim SQL As String
            SQL = " SELECT CO_ID,CH_STATUS,ENTDATE,CH_REASON,RS_ID,RS_DESC "
            SQL = SQL & " FROM CONTRACT_HISTORY CH,REASONSTATUS_ALL RS "
            SQL = SQL & " WHERE RS.RS_ID = CH.CH_REASON And CH_SEQNO>1 AND CO_ID = " & coid

            Return myDBConn.myORATable(SQL)
        End Function

        Public Shared Function getListItems(ByVal status As String) As DataTable
            Dim SQL As String

            SQL = "SELECT RS_ID,RS_DESC FROM REASONSTATUS_ALL WHERE RS_STATUS='"
            SQL = SQL & status & "'"
            SQL = SQL & " union select 0,' ' from reasonstatus_all where rownum<2"

            Return myDBConn.myORATable(SQL)
        End Function

        Public Shared Function updateContractHistory(ByVal reason As String, ByVal coid As String, ByVal seqno As String) As Long
            Dim SQL As String

            SQL = "update contract_history set ch_reason="
            SQL = SQL & reason
            SQL = SQL & " where co_id=" & coid & " and ch_seqno=" & seqno

            Return myDBConn.ORAExecute(SQL)

        End Function

        Public Shared Function getContractHistory(ByVal coid As String, ByVal seqno As String) As DataTable
            Dim SQL As String

            SQL = "select CO_ID,CH_SEQNO,CH_STATUS,RS.RS_ID,RS.RS_DESC "
            SQL = SQL & "from CONTRACT_HISTORY CH,REASONSTATUS_ALL RS "
            SQL = SQL & "WHERE RS.RS_ID = CH.CH_REASON And CO_ID =" & coid & " and ch_seqno=" & seqno

            Return myDBConn.myORATable(SQL)
        End Function

        Public Shared Function insertLog(ByVal coid As String, ByVal seqno As String, ByVal status As String, ByVal rsidOld As String, ByVal rsDescOld As String, ByVal rsidNew As String, ByVal rsDescNew As String, ByVal user As String) As Long
            Dim SQL As String

            SQL = "insert into REASON_UPDATE_LOG (CO_ID,CH_SEQNO,CH_STATUS,OLD_REASON_ID,OLD_REASON_DESC,"
            SQL = SQL & "NEW_REASON_ID,NEW_REASON_DESC,ENTRY_USER)"
            SQL = SQL & " VALUES (" & coid & "," & seqno & ",'" & status & "'," & rsidOld
            SQL = SQL & ",'" & rsDescOld & "'," & rsidNew & ",'" & rsDescNew & "','"
            SQL = SQL & user & "')"

            Return myDBConn.Execute(SQL)

        End Function

    End Class
End Namespace
